package kr.ac.hanyang.cs.jhpark;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.view.Window;
import android.view.WindowManager;

public class CastSkill {
	private Intent intent;
	private Activity activity;

	public static final String[][] SKILLSET = {
		{"외부 App 실행", 	"APP_LAUNCH"	}
		, {"전화걸기",		"CALL_TEL"		}
		, {"무선랜 켜기",		"WIFI_ON"		}
		, {"무선랜 끄기",		"WIFI_OFF"		}

	};



	public static final int STAT_OFF				= 0;
	public static final int STAT_ON					= 1;

	
	public CastSkill(Activity activity) {
		super();
		this.activity								= activity;
	}

	
	// return skill lists
	public static ArrayList<String[]> getSkillSet() {
		ArrayList<String[]> skillSet				= new ArrayList<String[]>();
		for (int i = 0;i < SKILLSET.length;i++) {
			skillSet.add(SKILLSET[i]);
		}

		return skillSet;
	}

	
    // launch application using given package name (String pkgName)
	public void launchApp(String pkgName) {
		// TODO: should be check whether package exists or not

		Intent LaunchIntent							= activity.getPackageManager().getLaunchIntentForPackage(pkgName);
		this.activity.startActivity(LaunchIntent);
	}


	// turn off screen
	public void screenOff() {
		// need permission (?)
		// <uses-permission android:name="android.permission.WAKE_LOCK" />
		
		// make screen brightness to zero
		Window myWindow								= activity.getWindow();
		WindowManager.LayoutParams lp				= myWindow.getAttributes();
		lp.screenBrightness							= 0;
		myWindow.setAttributes(lp);
	}

	
	// turn on/off wifi
	public void setWifi(int toBeStat) {
		// need permission
		// <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

		WifiManager wManager						= (WifiManager)activity.getSystemService(Context.WIFI_SERVICE);

		switch(toBeStat) {
			case STAT_ON:
				// turn on wifi
				wManager.setWifiEnabled(true);
				break;
			case STAT_OFF:
				// turn off wifi
				wManager.setWifiEnabled(false);
				break;
		}
	}
	

}
